import type { QueryPaginationParams, ResponsePaginationData } from '@/utils/request';
import { SUCCESS_CODE } from '@/utils/request';
import type { SpaceIncomeStatisticsData } from './data';
import { message } from 'antd';
import type { RequestData } from '@ant-design/pro-table';
import { request } from 'umi';

export interface QueryListParams extends QueryPaginationParams {
  zoneId?: string;
  spaceName?: string;
}

/**
 * 获取流水列表
 * @param params
 */
export async function querySpaceIncomeStatisticsDataList(
  params: QueryListParams,
): Promise<RequestData<SpaceIncomeStatisticsData>> {
  const res: ResponsePaginationData<SpaceIncomeStatisticsData> = await request(
    '/finance/statistics/get_space_profit_account_list',
    {
      params: params,
    },
  );

  if (!res || res.code !== SUCCESS_CODE) {
    message.error('获取失败');
    return { success: false, total: 0, data: [] };
  }

  return {
    success: true,
    total: res.data.total,
    data: res.data.list,
  };
}
